<?php
/*
 * @Author: lokei
 * @Date: 2022-12-30 17:28:40
 * @LastEditors: lokei
 * @LastEditTime: 2022-12-31 21:51:19
 * @Description: 
 */
namespace App\Http\Controllers\Widget;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Widget\ThemeModel;
use Illuminate\Http\Request;

class ThemeController extends Controller {
    public function get() {
        $theme = ThemeModel::first();
        if(is_null($theme)) {
            $theme = new ThemeModel();
            $theme->color = '#F27931';
            $theme->save();
        }
        $res = ResultTool::success();
        $res['data']['theme'] = $theme;
        return $res;
    }

    public function update(Request $request) {
        $theme = ThemeModel::first();
        $theme->color = $request->input('color');
        $theme->save();
        return ResultTool::success();
    }

    public function getMenu() {
        $theme = ThemeModel::first();
        if(is_null($theme)) {
            $theme = new ThemeModel();
            $theme->color = '#F27931';
            $theme->save();
        }
        $res = ResultTool::success();
        $res['data']['menu_theme'] = $theme->menu_theme;
        return $res;
    }

    public function setMenu(Request $request) {
        $theme = ThemeModel::first();
        $theme->menu_theme = $request->input('menu_theme');
        $theme->save();
        return ResultTool::success();
    }
}